package cn.edu.sdjzu.xg.bysj.service;

import cn.edu.sdjzu.xg.bysj.dao.GraduateProjectCategoryDao;
import cn.edu.sdjzu.xg.bysj.dao.GraduateProjectTruenessDao;
import cn.edu.sdjzu.xg.bysj.domain.GraduateProjectCategory;
import cn.edu.sdjzu.xg.bysj.domain.GraduateProjectTrueness;
import util.JdbcHelper;
import util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

public class GraduateProjectTruenessService {
    private GraduateProjectTruenessDao graduateProjectTruenessDao =
            GraduateProjectTruenessDao.getInstance();
    //本类的一个对象引用，保存自身对象
    private static GraduateProjectTruenessService graduateProjectTruenessService =
            new GraduateProjectTruenessService();
    //私有的构造方法，防止其它类创建它的对象
    private GraduateProjectTruenessService(){}
    //静态方法，返回本类的惟一对象
    public synchronized static GraduateProjectTruenessService getInstance() {

        return graduateProjectTruenessService;
    }

    public Collection<GraduateProjectTrueness> findAll(List conditionList,
                                                       Pagination pagination) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        Collection<GraduateProjectTrueness> graduateProjectTrueness =
                graduateProjectTruenessDao.findAll(conditionList,pagination,connection) ;
        JdbcHelper.close(connection);
        return graduateProjectTrueness;
    }

    public GraduateProjectTrueness find(Integer id) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        GraduateProjectTrueness graduateProjectTrueness = graduateProjectTruenessDao.find(id,connection);
        JdbcHelper.close(connection);
        return graduateProjectTrueness;
    }

    public boolean update(GraduateProjectTrueness graduateProjectTrueness) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        Boolean updated = graduateProjectTruenessDao.update(graduateProjectTrueness,connection);
        JdbcHelper.close(connection);
        return updated ;
    }

    public boolean add(GraduateProjectTrueness graduateProjectTrueness) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        Boolean added = graduateProjectTruenessDao.add(graduateProjectTrueness,connection);
        JdbcHelper.close(connection);
        return added ;
    }
    public boolean delete(Integer id) throws SQLException{
        Connection connection = JdbcHelper.getConn();
        boolean deleted = graduateProjectTruenessDao.delete(id, connection);
        JdbcHelper.close(connection);
        return deleted;
    }

    public boolean delete(GraduateProjectTrueness graduateProjectTrueness) throws SQLException{
        Connection connection = JdbcHelper.getConn();
        boolean deleted = graduateProjectTruenessDao.delete(graduateProjectTrueness, connection);
        JdbcHelper.close(connection);
        return deleted;
    }
}
